-
Notifications
You must be signed in to change notification settings - Fork 92
Fix #49: Add Scala.js support #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks @OlivierBlanvillain. I will take a look at the build failure https://travis-ci.org/scala/scala-xml/builds/163345736. And let the community take a look at this too. |
fc86cb2
to
7ffd49a
Compare
Build seems fine https://travis-ci.org/scala/scala-xml/builds/163353923. There seems intermittent download error. |
Yes, I rolled back the version of sbt (I updated it without a good reason anyway), the problem seems to come from repo.typesafe.com (sbt/sbt#2758). |
I'd encourage resubmitting that part once the sbt/sbt#2758 storm has passed UPDATE (Oct 3): That storm has passed. |
Wow, this would be a huge enabler for frontend Scala.js development. We are currently using Binding.scala in a medium sized project. Our designer loves using HTML syntax but he hates the abominable compilation times caused by the macro annotations that eliminate scala.xml._. One question, it seems |
@olafurpg Thanks for your feedback! |
I look forward to this being merged :) |
What would be the right way to test this ? Any ideas ? For a starter I will start with a basic scala.js app and try to use scala-xml and see how that pans out. |
Hum ... |
@sjrd thank you for pitching in. Really appreciate your views regarding scalajs support. I have gone through your post http://stackoverflow.com/questions/30143126/how-do-i-port-an-existing-scala-library-to-scalajs/30144349#30144349 and http://www.scala-js.org/doc/project/cross-build.html . To be clearer, my question would have been is this sufficient or do we need to have any more tests, to make sure the library works and behaves well when used with scala.js. |
It is as sufficient as the tests for the JVM. Everything that should work on both platform should be tested in |
@sjrd thanks for quick reply and regarding tests I got it. I think we should be good enough to go on this then. |
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)) | ||
|
||
lazy val xmlJVM = xml.jvm | ||
lazy val xmlJS = xml.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup of the build.sbt file and modernization for other compilers is great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the publish-signed
task work with the new changes to SBT? The admin/build.sh file is run by Travis, and when it's for a Git tag, it will copy the admin/publish-settings.sbt file to the root directory. Looks like it will cause SBT to fail to load:
$ env PGP_PASSPHRASE=foobar sbt
[info] Loading project definition from scala-xml/project
scala-xml/publish-settings.sbt:3: error: not found: value pgpPassphrase
pgpPassphrase := Some(env("PGP_PASSPHRASE").toArray)
^
@@ -0,0 +1,202 @@ | |||
// package scala.xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no plan to fix the tests, maybe just don't copy them over? Just remove them from the js/src/test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I agree.
// Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))), | ||
// Elem(null, "author", e, sc, Text("John Mitchell")), | ||
// Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, if no plan to support these tests for the ScalaJS test suite, then just delete instead of comment out?
* uses as many old nodes as possible. | ||
* | ||
* Three transformers class for case - | ||
* One for orginal, one for modified, and one proposed which shows | ||
* all are equivalent when it comes to reusing as many nodes as possible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the only changes to this file, ReuseNodesTests.scala, are changes to whitespace, maybe revert so as to avoid touching the file besides the rename. We can fix whitespace in another PR
@@ -96,7 +97,7 @@ abstract class CachedFileStorage(private val file1: File) extends Thread { | |||
val c = fos.getChannel() | |||
|
|||
// @todo: optimize | |||
val storageNode = <nodes>{ nodes.toList }</nodes> | |||
val storageNode = <nodes>{nodes.toList}</nodes> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file, CachedFileStorage.scala, also only has whitespace changes that should be preserved for now, IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that scalajs needs the directory structure to be divided by jvm and js and shared. This is like the 3rd time the directory structure will change significantly for this long living package. This would be a good time to get it right, since the current structure frustrates me since it is overly long. This PR will make it longer. Sorry to attempt to tack these directory issues on to a PR for ScalaJS support, but so it goes.
Currently, it is
src/main/scala/scala/xml/
src/test/scala/scala/xml/
It would be better if it was this, IMO
src/main/scala/
src/test/scala/
For this ScalaJS PR, the current change renames things to
xml/js/src/test/scala/scala/xml/
xml/jvm/src/test/scala/scala/xml/
xml/shared/src/main/scala/scala/xml/
xml/shared/src/test/scala/scala/xml/
js/src/test/scala/
jvm/src/test/scala/
shared/src/main/scala/
shared/src/test/scala/
I don't have Scalajs experience, so I apologize for making suggestions out of ignorance.
7ffd49a
to
419891f
Compare
@ashawley thanks for you detailed review! I've forced push 3 updated commits which address all of your comment. Regarding the For reference, I managed to |
Whether good or bad, this would go against commonly acknowledged practices. Moreover, this would confuse some IDEs. For the Scala.js thing, it might be better to achieve this:
which can be done with |
@OlivierBlanvillain Cool! Looks great, thanks. Yes, I missed that part of the build.sh script for publish-signed. @sjrd I'm familiar with the convention, but wasn't aware the folder structure was a requirement for IDEs. I had assumed they use code indexing and such -- regardless of folder names to resolve things. I'm an SBT and Emacs scala-mode person, so if it's an issue I'd have to defer to others who use such IDEs. |
419891f
to
2e32f76
Compare
Alright, structure is now as follows:
|
2e32f76
to
bbf0a23
Compare
bbf0a23
to
c2418f4
Compare
Rebased. Do you think this could get merged before 1.0.6? |
FWIW, here is a demonstration of what's possible with scala-xml on Scala.js: https://olivierblanvillain.github.io/monadic-html/examples/ The demo uses a fork of scala-xml, it would be nice to depend on the official scala-xml module. |
@biswanaths @ashawley shall we merge? |
LGTM. I appreciate @OlivierBlanvillain's willingness to minimize the file changes, and for entertaining my directory renaming wishes: Even if in the end, my whims were misguided. I assume adding Scalacheck in #110 will require a similar pattern of disabling certain tests for ScalaJS? |
Correct. |
@SethTisue , sure enough. I think community had enough time to go through this. I will go through the changes once again. And pull it in. |
c2418f4
to
834bfab
Compare
Any other issues with this? Would really like to see it merged. |
@biswanaths @SethTisue @ashawley Nudge, anything I/we can do to help get this in? I'd like to see it for scala.js, and once this is in, maybe experiment with using it in scala-native as well. |
(the Scala team doesn't need to be the gatekeeper on everything in this repo, but this an especially juicy PR and there seems to be a consensus on merging it, and certainly plenty of review time passed, so I went ahead in this case) |
Travis build error for Java 8 and Scala 2.12:
|
huh, I don't know how I missed that, I thought I looked at the Travis results, maybe they were somehow not current. I'll prepare a followup PR right now with a fix. |
this is required to fix Travis failures after scala#109 was merged
thank you, Olivier, for this truly substantial contribution! |
So will tests need to be added to both JS and JVM trees going forward? Was there an option to have SBT run common tests between both Scala compilers? |
@ashawley Cross platform tests should go in |
That's right, |
@ashawley Let me open a new PR doing that |
This PR adds Scala.js support.
The changes are pretty straightforward. After updating the bulid, a52ca9c moves files around to cope with the Scala.js
jvm/js/shared
folder structure. Almost everything goes to/shared
, except for the few test cases that lead to linking errors on Scala.js. Then fc86cb2 copies the problematic tests to/js
and manually comments the parts involving JVM specific stuff such as accesses to the file system.I think the prime use case for xml literals in Scala.js is to generate equivalent
org.scalajs.dom.raw.Node
, which does not require any of the JVM specific parts of the library. Binding.scala and scala-js-react are already doing this by the mean of macros: they get ride of everything coming fromscala.xml._
at compile time. This approach unfortunately leads to long compilation times. Using xml literals natively from Scala.js (probably with a run time transformation toorg.scalajs.dom.raw.Node
) would leads to much better compilation time.